import collections
class Solution(object):
    def canTransform(self, start, end):
        n = len(start)
        index1 = 0
        index2 = 0
        c1 = collections.Counter(start)
        c2 = collections.Counter(end)
        if c1 != c2:
            return False
        while index1 < n and index2 < n:
            if start[index1] == 'X':
                index1 += 1
            else:
                if end[index2] == 'X':
                    index2 += 1
                else:
                    if start[index1] != end[index2]:
                        return False
                    else:
                        if start[index1] == 'L':
                            if index1 < index2:
                                return False
                        else:
                            if index1 > index2:
                                return False
                        index1 += 1
                        index2 += 1
        return True


data = Solution()
start = "RXXLRXRXL"
end = "XRLXXRRLX"
print(data.canTransform(start, end))
